package cn.iocoder.yudao.module.trade.dal.mysql.giftcard;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.trade.controller.admin.giftcard.vo.CardGroupPageReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.giftcard.vo.CardPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.giftcard.GiftCardDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.giftcard.GiftCardGroupDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface GiftCardGroupMapper extends BaseMapperX<GiftCardGroupDO> {

    default List<GiftCardGroupDO> selectListByCardId(String cardId,Integer groupType) {
        return selectList(new LambdaUpdateWrapper<GiftCardGroupDO>()
                .eq(GiftCardGroupDO::getWxCardId, cardId)
                .eq(GiftCardGroupDO::getGroupType, groupType)
                .orderByDesc(GiftCardGroupDO::getCreateTime));
    }

    default PageResult<GiftCardGroupDO> selectPage(CardGroupPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<GiftCardGroupDO>()
                .likeIfPresent(GiftCardGroupDO::getGroupName, reqVO.getGroupName())
                .eqIfPresent(GiftCardGroupDO::getWxCardId, reqVO.getWxCardId())
                .orderByDesc(GiftCardGroupDO::getId));
    }

}
